package com.wc.算法基础课.E第五讲动态规划.数位统计DP.windy数;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/18 11:15
 * @description https://www.luogu.com.cn/problem/P2657
 */
public class Main {
    static int a, b;
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 15;
    // f[i][j] 表示一共有i位，最高位为j的个数
    static int[][] f = new int[N][10];
    static int[] nums = new int[N];

    static void init() {
        for (int i = 0; i <= 9; i++) f[1][i] = 1;
        for (int i = 2; i < N; i++) {
            for (int j = 0; j <= 9; j++) {
                for (int k = 0; k <= 9; k++) {
                    if (Math.abs(j - k) >= 2)
                        f[i][j] += f[i - 1][k];
                }
            }
        }
    }

    public static void main(String[] args) {
        a = sc.nextInt();
        b = sc.nextInt();
        init();
        out.println(dp(b) - dp(a - 1));
        out.flush();
    }

    static int dp(int n) {
        if (n == 0) return 0;
        int len = 0;
        while (n > 0) {
            nums[len++] = n % 10;
            n /= 10;
        }
        int res = 0;
        int last = -2;
        for (int i = len - 1; i >= 0; i--) {
            int x = nums[i];
            // 最高位置需要从1开始
            for (int j = i == len - 1 ? 1 : 0; j < x; j++) {
                if (Math.abs(j - last) >= 2) {
                    // 从i位到0位一共i+1位数
                    res += f[i + 1][j];
                }
            }
            if (Math.abs(x - last) >= 2) last = x;
            else break;

            if (i == 0) res++;
        }
        // 特殊枚举下， 处理有前导0的数,相当于1位数到len位数满足条件的所有数的总和
        for (int i = 1; i < len; i++) {
            for (int j = 1; j <= 9; j++) {
                res += f[i][j];
            }
        }
        return res;
    }

}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
